<?php
/**
 * Created by PhpStorm.
 * User: Mak
 * Date: 2016/2/6
 * Time: 19:14
 */

namespace Home\Controller;
use Org\Util\Snoopy;
use Think\Controller;

class GgController extends Controller{

    public function _initialize(){
        header("content-type:text/html; charset=utf-8");
        $flag = session("?Account");
        if(!$flag){
            $this->error("非法登录",U('Home/Index/index'));
        }
    }

    public function index(){
        $sn=new Snoopy();
        $sn->cookies= session("cookies");
        $sn->proxy_host=session("ip.ip");
        $sn->proxy_port=session("ip.port");
        $sn->agent = "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko";
        $sn->referer = "http://jw.gxsdxy.cn/jiaowures/";
        $sn->rawheaders['Pragma'] = 'no-cache';
        $sn->rawheaders['X_FORWARDED_FOR'] = "jw.gxsdxy.cn";
        $sn->fetch("http://jw.gxsdxy.cn/jiaowures/JWXS/OA_DESK.aspx");

        $ret=mb_convert_encoding($sn->results,"utf-8","gb2312");

        $pattern = '/<table cellspacing="1" cellpadding="1" rules="all" Border="0" border="1" id="GridView1" style="width:100%;">(.*?)<\/table>/is';
        preg_match_all($pattern, $ret, $matches);

        $pattern = "/GGTZID=(.*?)'/is";
        preg_match_all($pattern, $matches[1][0], $matches2);

        $pattern = '/<tr>(.*?)<\/tr>/is';
        preg_match_all($pattern, $matches[1][0], $matches);

        $rstr=array();
        for($i=0;$i<count($matches2[1]);$i++){
            $tmp=preg_replace("/\.\./","http://jw.gxsdxy.cn/jiaowures",$matches[1][$i]);
            $rstr=array(preg_replace("/#/",U("Gg/xq?id={$matches2[1][$i]}"),$tmp)) ;
        }


        $this->assign("jwgg",$rstr);
        $this->assign("title","教务系统信息公告");
        $this->display();
    }

    public function xq(){


        $GGTZID=I("get.id");

        $sn=new Snoopy();
        $sn->cookies= session("cookies");
        $sn->proxy_host=session("ip.ip");
        $sn->proxy_port=session("ip.port");
        $sn->agent = "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko";
        $sn->referer = "http://jw.gxsdxy.cn/jiaowures/";
        $sn->rawheaders['Pragma'] = 'no-cache';
        $sn->rawheaders['X_FORWARDED_FOR'] = "jw.gxsdxy.cn";
        $sn->fetch("http://jw.gxsdxy.cn/jiaowures/JWXS/ShowGGTZ.aspx?GGTZID={$GGTZID}");

        $ret=mb_convert_encoding($sn->results,"utf-8","gb2312");

        $pattern = '/<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" class="bg" bgcolor="#FFFFFF" text="#000000" vlink="#000000">(.*?)<\/body>/is';
        preg_match_all($pattern, $ret, $matches);
        $tmp=preg_replace("/\.\./","http://jw.gxsdxy.cn/jiaowures",$matches[1][0]);

        $pattern = '/<title>(.*?)<\/title>/is';
        preg_match_all($pattern, $ret, $title);

        $this->assign("gg",$tmp)->assign("title",$title[1][0]);
        $this->display();
    }
}